from core.basehandler import BaseHandler
from core.room import Room
from core.action import Action
from core.support import set_cutscene
from core.support import get_game
from items.decryptor import Decryptor

class HardDrive(Room):
    def __init__(self, room_id):
        Room.__init__(self, room_id)    # do basic initialization for every room
        
        # build list of actions
        self.add_action(West)
    
    # return description of room.
    def get_description(self):
        if self.has_decryptor():
            return '''
            You see an enormous disk that's spinning right round, baby right round like a record, baby. That handy defragmenter really
            cleared things up... and opened up a new direction!
            '''
        else:
            return '''
            JFH KSW GN RMIRASJD GJIF UJTS'H KDJUUNET WINCT JANDY, NADJE WOWEN JANDY LWNF G NSMDOR, JAJI.
            '''
    
    # return image of room
    def get_image(self):
        if self.has_decryptor():
            return 'Hard_Drive_Cut_.gif'
        else:
            return 'binary_hd.gif'
        #return 'ramram.png'
    
    def get_image_width(self):
        return 'width=555px;'
    
    def is_translated(self):
        
        game = get_game()
            
        # does the player have ASCII from the register?
        player = game.get_player()
        
        if "Translator" in player.inventory:
            return True
        # if we get here, player does not have ASCII
        return False
    
    def has_decryptor(self):
        
        game = get_game()
            
        # does the player have ASCII from the register?
        player = game.get_player()
        
        if "Decryptor" in player.inventory:
            return True
        # if we get here, player does not have ASCII
        return False

class HardDriveHandler(BaseHandler):
    
    def get_template(self):
        return 'cpu.html'
    
    # return class to use to create a new instance of this room
    def get_room_class(self):
        return HardDrive
    
    def update(self,request_type):
        if self.get_this_room().has_decryptor():
            self.get_this_room().add_action(East)
        BaseHandler.update(self, request_type);

# define actions for this room

class East(Action):
    def __init__(self):
        Action.__init__(self, "East")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        game = get_game()
        room = game.get_room("harddrive", HardDrive)
        if room.has_decryptor():
            return "Go East"
        else:
            return "JU AKJD"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'ramroom'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def post_method(self):
        return "get"

class West(Action):
    def __init__(self):
        Action.__init__(self, "West")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        game = get_game()
        room = game.get_room("harddrive", HardDrive)
        if room.has_decryptor():
            return "Go West"
        else:
            return "JU HNFG"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'Binary_Monster'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"
